package com.atguigu.daijia.driver.client.fallback;

import com.atguigu.daijia.common.execption.GuiguException;
import com.atguigu.daijia.common.result.Result;
import com.atguigu.daijia.common.result.ResultCodeEnum;
import com.atguigu.daijia.driver.client.DriverAccountFeignClient;
import com.atguigu.daijia.model.form.driver.TransferForm;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * @create: 2024/10/2
 * @author: gyhe10
 * @description: DriverAccountFeignClient 接口的降级实现工厂类
 **/

@Component
public class DriverAccountFeignClientFallbackFactory implements FallbackFactory<DriverAccountFeignClient> {
    @Override
    public DriverAccountFeignClient create(Throwable cause) {
        return new DriverAccountFeignClient() {
            @Override
            public Result<Boolean> transfer(TransferForm transferForm) {
                if (cause instanceof GuiguException) {
                    return Result.build(null, ((GuiguException) cause).getCode(), cause.getMessage());
                } else {
                    return Result.build(null, ResultCodeEnum.FEIGN_FAIL);
                }
            }
        };
    }
}
